package com.lanqiao.attendance.controller;

import com.lanqiao.attendance.handler.TeacherHandler.TeacherExceptionCatch;
import com.lanqiao.attendance.handler.TeacherHandler.TeacherTokenVerify;
import com.lanqiao.attendance.pojo.Teacher;
import com.lanqiao.attendance.service.TeacherService;
import com.lanqiao.attendance.vo.LoginParam;
import com.lanqiao.attendance.vo.LoginParam2;
import com.lanqiao.attendance.vo.Result;
import com.lanqiao.attendance.vo.TeacherVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * * @Author Pu Yunsheng
 * * @Data 2022/7/9 下午 05:10
 * * @Version 1.0
 **/

@RestController
@RequestMapping("teacher")
@Api(description = "教师控制类")
public class TeacherController {

    @Resource(name = "teacherServiceImpl")
    TeacherService teacherService;

    @PostMapping("login")
    public Result login(@RequestBody LoginParam2 loginParam){
        return teacherService.login(loginParam);
    }


    @PutMapping("/register")
    @TeacherExceptionCatch //异常提示
    @ApiOperation("教师注册---------账号，密码，名字不能为空")
    public Result register(@RequestBody @ApiParam("教师对象") TeacherVo teacherVo){
        return teacherService.register(teacherVo);
    }

    @PostMapping("add")
    @ApiOperation("添加教师---------账号，密码，名字不能为空")
//    @TeacherExceptionCatch //异常提示
//    @TeacherTokenVerify   //token检验
    public Result addTeacher(@RequestBody @ApiParam("教师对象") TeacherVo teacherVo){
        return teacherService.addTeacher(teacherVo);
    }

    @GetMapping("queryNameByAccount")
    public Result queryNameByAccount(String account){
        System.out.println(account);
        String name=  teacherService.queryNameByAccount(account);
        return Result.success("查询成功",name);
    }

    @PostMapping("delete")
    @ApiOperation("删除教师---------账号不能不为空")
//    @TeacherExceptionCatch //异常提示
//    @TeacherTokenVerify   //token检验
    public Result delete(@RequestBody @ApiParam("教师") Teacher teacher){
        System.out.println(teacher.getAccount());
        String account = teacher.getAccount();
        return teacherService.deleteTeacher(account);
    }

    @GetMapping("info/{account}")
    @ApiOperation("获取教师信息---------账号不能为空")
//    @TeacherExceptionCatch //异常提示
//    @TeacherTokenVerify   //token检验
    public Result getTeacherInfo(@PathVariable("account") @ApiParam("教师账号")String account){
        return teacherService.getTeacherByNum(account);
    }

    @GetMapping("all")
    @ApiOperation("获取全部教师信息---------无参数")
//    @TeacherExceptionCatch //异常提示
//    @TeacherTokenVerify   //token检验
    public Result getAllTeacherInfo(){
        return teacherService.getAllTeacher();
    }



    @PostMapping("/update")
    @ApiOperation("更新教师信息---------账号，密码，名字不能为空")
//    @TeacherExceptionCatch //异常提示
//    @TeacherTokenVerify   //token检
    public Result updateTeacher(@RequestBody @ApiParam("教师对象") TeacherVo teacherVo){

        System.out.println("777"+teacherVo);
        return teacherService.updateTeacher(teacherVo);
    }


    @ApiOperation("教师信息分页查询---------页码，页容量不能为空")
//    @TeacherExceptionCatch //异常提示
//    @TeacherTokenVerify   //token检验
    @GetMapping("/pageQuery/page/{pageNumber}/number/{pageSize}")
    public Result pageQuery(@PathVariable("pageNumber") Integer pageNum,
                            @PathVariable("pageSize") Integer pageSize){
        return teacherService.pageQuery(pageNum,pageSize);
    }
}
